package com.song.service.impl;

import com.song.mapper.EmpMapper;
import com.song.mapper.StudentMapper;
import com.song.pojo.ClazzStudentCount;
import com.song.pojo.JobOption;
import com.song.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceIml implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption getEmpsJobDetail() {
        JobOption jobOption = new JobOption();
        List<Map<String, Object>> list = empMapper.getEmpsJobDetail();
        //Map集合:[{"职位":"java","数量":10}]
        jobOption.setJobList( list.stream().map(dataMap->dataMap.get("职位")).toList());
        jobOption.setDataList( list.stream().map(dataMap->dataMap.get("数量")).toList());
        return jobOption;
    }

    @Override
    public List getEmpsGenderDetail() {

        //Map集合:[{"name":"男","value":10}]
       return empMapper.getEmpsGenderDetail();
    }

    @Override
    public List getStudentsDegreeDetail() {
      List<Map<String, Object>> list = studentMapper.getStudentsDegreeDetail();
      //Map集合:[{"name":1,"value":10}]
      list.forEach(dataMap->{
          if(dataMap.get("name").equals(1)){
              dataMap.put("name","初中");
          }else if(dataMap.get("name").equals(2)){
              dataMap.put("name","高中");
          }else if(dataMap.get("name").equals(3)){
              dataMap.put("name","大专");
          }else if(dataMap.get("name").equals(4)){
              dataMap.put("name","本科");
          }else if(dataMap.get("name").equals(5)){
              dataMap.put("name","硕士");
          }else{
              dataMap.put("name","博士");
          }
      });
      return list;
    }

    @Override
    public ClazzStudentCount getStudentsCountDetail() {
       List<Map<String, Object>> list = studentMapper.getStudentsCountDetail();
       ClazzStudentCount clazzStudentCount = new ClazzStudentCount();
       clazzStudentCount.setClazzList( list.stream().map(dataMap->dataMap.get("班级名称")).toList());
       clazzStudentCount.setDataList( list.stream().map(dataMap->dataMap.get("学生数量")).toList());
       return clazzStudentCount;
    }
}
